<?php

/**
 * 本页仅供测试
 */
class IndexAction extends Action {

    protected function _initialize() {
        header("Content-Type:text/html; charset=utf-8");
    }

    public function index() {
        $this->display();
    }
    public function test(){
        $this->display();
        
    }

    //注册
    public function register(){
        import("@.ORG.Jssdk");
        $jssdk = new JSSDK("wxb0b320ddeaae8666", "0f5e197979b0cdc6bd8fe6cf1f57a0c0");
        $signPackage = $jssdk->GetSignPackage(); 
        $STU = D('Student/StudentInfo');
        $banji = M('admin_class')->select();
        $openId = I('openId');
        session('openId',$openId);
        if($STU->where('openId = "'.$openId.'"')->find())
            $this->error("你已经注册过了，请联系平台管理员");
        $this->assign('signPackage',$signPackage);
        $this->assign('openId',$openId);
        $this->assign('banji',$banji);
        $this->display();
    }
    public function handleRegister(){
        /**
         *  author : lijj  
         *time : 2016-3-3
         *不足之处，在界面方面，注册成功后，没有一个很友善的界面
         *在选择班级方面的逻辑判断还不对
         */
        //用ajax将获得的数据存入数据库 ， 然后跳转至微信平台
        $info = array(
                'openId' => I('openId'),
                'name' => I('name'),
                'number' => I('number'),
                'class' => I('class') ,
                'password' => I('password'),
                'time' => date('Y-m-d H:i:s'),
            );
        M('student_info')->data($info)->add();
    }

    public function handlechangePersonInfo(){
        //这个功能的主要问题是没有在js中使用函数，在对数据合法性判断时，代码冗余
        if(!IS_AJAX)
            $this->error('你访问的界面不存在');
        $openId = session('openId');
        $infoChange = array(
                'openId' => $openId,
                'name' => I('name'),
                'number' => I('number'),
                'class' => I('banji'),
            );
        M('student_info')->where('openId="'.$openId.'"')->data($infoChange)->save();
        $this->ajaxReturn(array('status' => 'success'),'json');

        
    }

    //修改信息
    public function changeInfo(){
        $openId = session('?openId') ? session('openId') : $this->error('你请求的页面不存在，请在微信端重新获取链接');
        $info = M('student_info')->where('openId="'.$openId.'"')->find();
        $banji = M('admin_class')->select();
        $this->assign('info',$info);
        $this->assign('banji',$banji);
        // p($class);
        $this->display();
        // p($info);
    }

    public function authenticate(){
        $openId = I('openId')?:$this->error('你请求的页面不存在');
        $STU = D('Student/StudentInfo');
        // 判断下否已经注册
        // R('User/info') //表示调用当前项目的User模块的info操作方法
        if(!$STU->where('openId = "'.$openId.'"')->find())
            $this->error('你还没有注册，请注册',U('Index/register').'?openId='.$openId);
        session('openId',$openId);
        if(!session('?openId'))
            $this->error('操作失败，请联系后台管理员');
        $this->success('操作成功，请手动关闭该界面');
    }
}

?>

